<?php
session_start();
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/database.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/functions.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/class.admin.php');
//ini_set('display_errors',1);
$admin=new admin();
$admin->canView($_SERVER['PHP_SELF']);

$cachekey=DATABASE.'cached_page_'.$_POST['page_id'];
//print_r($_POST);
$admin->pageId($_POST['page_id']);
$is_parent=($_POST['page_parent']=='') ? 1 : 0;
$parent=($is_parent==1) ? '' : $_POST['page_parent'];
$groups=(count($_POST['page_group'])>=1) ? $_POST['page_group']  : array(); // array
//print_r($groups);
$content=$admin->clean($_POST['page_content']);
$item=array('$set'=>
					array(	'active'=>intval($_POST['page_active']),
							'text'=>$_POST['page_text'],
							'url'=>$_POST['page_url'],
							'parent'=>$_POST['page_parent'],
							'heading'=>$_POST['page_heading'],
							'is_parent'=>intval($is_parent),
							'order'=>intval($_POST['page_order']),
							'sidebar'=>intval($_POST['page_include_sidebar']),
							'requires_auth'=>intval($_POST['page_requires_auth']),
							'cache'=>intval($_POST['page_cache']),
							'is_blog'=>intval($_POST['page_is_blog']),
							'include_in_nav'=>intval($_POST['page_include_in_nav']),
							'groups'=>$groups,
							'meta'=>array(
											'keywords'=>$_POST['meta_page_keywords'],
											'title'=>$_POST['meta_page_title'],
											'description'=>$_POST['meta_page_description'],
											'custom'=>$_POST['meta_page_custom']
											
							
							),
							'tags'=>$admin->explode_trim($_POST['content_tags']))
			);
			if($_POST['page_is_blog']==0) {
				$item['$set']['content']=$content;	
			}

$admin->updateContent($item);
$admin->expireCache($cachekey);

?>
<script>$.fn.message('show','<div class="ok_h_message"><h2>Page updated</h2><p><strong>The page has been saved</strong></p></div>');</script>



